package com.zhima.util;

import cn.hutool.json.JSONUtil;
import com.zhima.enums.Judge0RequestParamEnums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : zhima
 * @date : 2023-09-07 08:20
 **/
public class RequestBodyBuilder {
    private final Map<String, Object> requestBody;

    private RequestBodyBuilder() {
        requestBody = new HashMap<>();
    }

    public static RequestBodyBuilder builder() {
        return new RequestBodyBuilder();
    }

    public RequestBodyBuilder addValue(String key, Object value) {
        requestBody.put(key, value);
        return this;
    }

    public String build() {
        return JSONUtil.toJsonStr(requestBody);
    }

    public RequestBodyBuilder addValue(Judge0RequestParamEnums requestParam, Object value) {
        requestBody.put(requestParam.getParamName(), value);
        return this;
    }

    public Map<String, Object> get() {
        return requestBody;
    }
}
